from toee import *
from utilities import *

def san_dialog( attachee, triggerer ):
	if (attachee.has_met(triggerer)):
		triggerer.begin_dialog( attachee, 110 )
	else:
		triggerer.begin_dialog( attachee, 100 )	
	return SKIP_DEFAULT

def san_heartbeat( attachee, triggerer ):
	if (not game.combat_is_active()):
		if ( game.global_vars[996] == 5 ):
			if (is_better_to_talk(attachee, game.party[0])):
				attachee.turn_towards(game.party[0])
				game.party[0].begin_dialog( attachee, 1 )
	return RUN_DEFAULT

def is_better_to_talk(speaker,listener):
	if (speaker.can_see(listener)):
		if (speaker.distance_to(listener) <= 30):
			return 1
	return 0

def switch_to_tarah( attachee, triggerer, line):
	npc = find_npc_near(attachee,8805)
	if (npc != OBJ_HANDLE_NULL):
		triggerer.begin_dialog(npc, line)
	return SKIP_DEFAULT

def san_first_heartbeat( attachee, triggerer ):
	if (attachee.map == 5060 and game.global_vars[993] == 3):
		attachee.object_flag_unset(OF_OFF)
	return RUN_DEFAULT

def slavers_leave_nulb( attachee, triggerer ):
	game.timevent_add( slavers_left_nulb, ( attachee, ), 172800000 )
	return RUN_DEFAULT

def slavers_left_nulb( attachee ):
	attachee.object_flag_set(OF_OFF)
	sharar = find_npc_near(attachee,8806)
	sharar.object_flag_set(OF_OFF)
	gadham = find_npc_near(attachee,8807)
	gadham.object_flag_set(OF_OFF)
	abaddon = find_npc_near(attachee,8808)
	abaddon.object_flag_set(OF_OFF)
	eran = find_npc_near(attachee,8809)
	eran.object_flag_set(OF_OFF)
	game.global_vars[993] = 4
	return RUN_DEFAULT